using System;
using System.Collections.Generic;
using System.Text;
using BussinessObjects.BO_Actions.Threads;
using Entity.StoreProcedure;
using System.Data;
namespace BusinessObjects.BO_GetObjects
{
    public static class BO_Threads
    {
        public static DataTable SelectAll(int status)
        {
            try
            {
                BOThreads_Select_All action = new BOThreads_Select_All();
                usp_Threads_Select_All entity = new usp_Threads_Select_All();
                entity.STATUS = status;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectTopVipHome(int rows, int status)
        {
            try
            {
                BOThreads_Select_Top_Vip_Home action = new BOThreads_Select_Top_Vip_Home();
                usp_Threads_Select_Top_Vip_Home entity = new usp_Threads_Select_Top_Vip_Home();
                entity.NUMBERRECORD = rows;
                entity.STATUS = status;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectTop(int rows, int status)
        {
            try
            {
                BOThreads_Select_Top action = new BOThreads_Select_Top();
                usp_Threads_Select_Top entity = new usp_Threads_Select_Top();
                entity.NUMBERRECORD = rows;
                entity.STATUS = status;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectMostView(int rows, int status)
        {
            try
            {
                BOThreads_Select_MostView action = new BOThreads_Select_MostView();
                usp_Threads_Select_MostView entity = new usp_Threads_Select_MostView();
                entity.NUMBERRECORD = rows;
                entity.STATUS = status;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectRandom(int category, int rows, int status, DateTime startdate)
        {
            try
            {
                BOThreads_Select_Random action = new BOThreads_Select_Random();
                usp_Threads_Select_Random entity = new usp_Threads_Select_Random();
                entity.CATEGORY = category;
                entity.NUMBERRECORD = rows;
                entity.STATUS = status;
                entity.STARTDATE = startdate;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectTopVip(int category, int rows, int status)
        {
            try
            {
                BOThreads_Select_Top_Vip action = new BOThreads_Select_Top_Vip();
                usp_Threads_Select_Top_Vip entity = new usp_Threads_Select_Top_Vip();
                entity.NUMBERRECORD = rows;
                entity.STATUS = status;
                entity.CATEGORY = category;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable Search(int thread_id)
        {
            try
            {
                BOThreads_Search action = new BOThreads_Search();
                usp_Threads_Search entity = new usp_Threads_Search();
                entity.THREAD_ID = thread_id;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string ExistThreadCode(string thread_code)
        {
            try
            {
                BOThreads_Exist_Thread_Code action = new BOThreads_Exist_Thread_Code();
                usp_Threads_Exist_Thread_Code entity = new usp_Threads_Exist_Thread_Code();
                entity.THREAD_CODE = thread_code;

                return action.ExecuteAndReturnStringValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string SelectTotalByParent(int category_id)
        {
            try
            {
                BOThreads_SelectTotal_By_Parent_Category action = new BOThreads_SelectTotal_By_Parent_Category();
                usp_Threads_SelectTotal_By_Parent_Category entity = new usp_Threads_SelectTotal_By_Parent_Category();
                entity.CATEGORY_ID = category_id;

                return action.ExecuteAndReturnStringValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectFilter(int category, int region_id, int need_id, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_Filter action = new BOThreads_Select_Filter();
                usp_Threads_Select_Filter entity = new usp_Threads_Select_Filter();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CATEGORY_ID = category;
                entity.NEED_ID = need_id;
                entity.REGION_ID = region_id;
                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectFliter(int category, int region_id, int need_id, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_Fliter action = new BOThreads_Select_Fliter();
                usp_Threads_Select_Fliter entity = new usp_Threads_Select_Fliter();
                entity.CATEGORY_ID = category;
                entity.NEED_ID = need_id;
                entity.REGION_ID = region_id;
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectFilterTest(int category, int is_category, int region_id, int is_province, int need_id, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_Filter_Test action = new BOThreads_Select_Filter_Test();
                usp_Threads_Select_Filter_Test entity = new usp_Threads_Select_Filter_Test();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CATEGORY_ID = category;
                entity.NEED_ID = need_id;
                entity.REGION_ID = region_id;
                entity.IS_CATEGORY = is_category;
                entity.IS_PROVINCE = is_province;
                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectFilterProvince(int category, int region_id, int need_id, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_Filter_Province action = new BOThreads_Select_Filter_Province();
                usp_Threads_Select_Filter_Province entity = new usp_Threads_Select_Filter_Province();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CATEGORY_ID = category;
                entity.NEED_ID = need_id;
                entity.REGION_ID = region_id;
                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectWithPaged(int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_WithPaged action = new BOThreads_Select_WithPaged();
                usp_Threads_Select_WithPaged entity = new usp_Threads_Select_WithPaged();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SearchLike(string keyword, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Search_like action = new BOThreads_Search_like();
                usp_Threads_Search_Like entity = new usp_Threads_Search_Like();
                entity.KEYWORD = keyword;
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectNeed(int need, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_Need action = new BOThreads_Select_Need();
                usp_Threads_Select_Need entity = new usp_Threads_Select_Need();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.NEED = need;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectNeedDistrict(int need, int startIndex, int pageCount, int status, int district)
        {
            try
            {
                BOThreads_Select_Need_District action = new BOThreads_Select_Need_District();
                usp_Threads_Select_Need_District entity = new usp_Threads_Select_Need_District();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.NEED = need;
                entity.REGION_ID = district;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectCategories(int category, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Select_Categories action = new BOThreads_Select_Categories();
                usp_Threads_Select_Categories entity = new usp_Threads_Select_Categories();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CATEGORY = category;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectCategoriesDistrict(int category, int startIndex, int pageCount, int status, int district)
        {
            try
            {
                BOThreads_Select_Categories_District action = new BOThreads_Select_Categories_District();
                usp_Threads_Select_Categories_District entity = new usp_Threads_Select_Categories_District();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CATEGORY = category;
                entity.REGION_ID = district;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SearchByTitle(int category, string title, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Search_By_Title action = new BOThreads_Search_By_Title();
                usp_Threads_Search_By_Title entity = new usp_Threads_Search_By_Title();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CATEGORY = category;
                entity.TITLE = title;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SearchAllByTitle(string title, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Search_All_By_Title action = new BOThreads_Search_All_By_Title();
                usp_Threads_Search_All_By_Title entity = new usp_Threads_Search_All_By_Title();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;

                entity.TITLE = title;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SearchBySender(string user_name, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Search_By_Sender action = new BOThreads_Search_By_Sender();
                usp_Threads_Search_By_Sender entity = new usp_Threads_Search_By_Sender();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.SENDER = user_name;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SearchByCode(string code, int startIndex, int pageCount, int status)
        {
            try
            {
                BOThreads_Search_By_Code action = new BOThreads_Search_By_Code();
                usp_Threads_Search_By_Code entity = new usp_Threads_Search_By_Code();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.STATUS = status;
                entity.CODE = code;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string DeleteByThreadCode(string code)
        {
            try
            {
                BOThreads_DeleteByThreadCode action = new BOThreads_DeleteByThreadCode();
                usp_Threads_DeleteByThreadCode entity = new usp_Threads_DeleteByThreadCode();
                entity.THREAD_CODE = long.Parse(code);

                return action.ExecuteAndReturnStringValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string Insert(string user_name, string password, string thread_code, int total_up, int total_sms, int add_type, int category_id, Int64 member_id, int need_id, int region_id, string thread_title, string thread_details, int total_view, int total_comments, bool is_vip, DateTime vip_date, bool is_display_on_homepage, string module_id, DateTime created_date, string created_by, DateTime modify_date, string modify_by, string last_post_by, DateTime last_post_date, bool status)
        {
            try
            {
                BOThreads_Insert action = new BOThreads_Insert();
                usp_Threads_Insert entity = new usp_Threads_Insert();
                entity.THREAD_CODE = thread_code;
                entity.TOTAL_UP = total_up;
                entity.TOTAL_SMS = total_sms;
                entity.ADD_TYPE = add_type;
                entity.CATEGORY_ID = category_id;
                entity.MEMBER_ID = member_id;
                entity.NEED_ID = need_id;
                entity.REGION_ID = region_id;
                entity.THREAD_TITLE = thread_title;
                entity.THREAD_DETAILS = thread_details;
                entity.TOTAL_VIEW = total_view;
                entity.TOTAL_COMMENTS = total_comments;
                entity.IS_VIP = is_vip;
                entity.VIP_DATE = vip_date;
                entity.IS_DISPLAY_ON_HOMEPAGE = is_display_on_homepage;
                entity.MODULE_ID = module_id;
                entity.CREATED_DATE = created_date;
                entity.CREATED_BY = created_by;
                entity.MODIFY_DATE = modify_date;
                entity.MODIFY_BY = modify_by;
                entity.LAST_POST_BY = last_post_by;
                entity.LAST_POST_DATE = last_post_date;
                entity.STATUS = status;
                entity.USER_NAME = user_name;
                entity.PASSWORD = password;
                return action.ExecuteAndReturnStringValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static string Update(Int64 thread_id, string thread_code, int total_up, int total_sms, int add_type, int category_id, Int64 member_id, int need_id, int region_id, string thread_title, string thread_details, int total_view, int total_comments, bool is_vip, DateTime vip_date, bool is_display_on_homepage, string module_id, DateTime created_date, string created_by, DateTime modify_date, string modify_by, string last_post_by, DateTime last_post_date, bool status)
        {
            try
            {
                BOThreads_Update action = new BOThreads_Update();
                usp_Threads_Update entity = new usp_Threads_Update();
                entity.THREAD_ID = thread_id;
                entity.THREAD_CODE = thread_code;
                entity.TOTAL_UP = total_up;
                entity.TOTAL_SMS = total_sms;
                entity.ADD_TYPE = add_type;
                entity.CATEGORY_ID = category_id;
                entity.MEMBER_ID = member_id;
                entity.NEED_ID = need_id;
                entity.REGION_ID = region_id;
                entity.THREAD_TITLE = thread_title;
                entity.THREAD_DETAILS = thread_details;
                entity.TOTAL_VIEW = total_view;
                entity.TOTAL_COMMENTS = total_comments;
                entity.IS_VIP = is_vip;
                entity.VIP_DATE = vip_date;
                entity.IS_DISPLAY_ON_HOMEPAGE = is_display_on_homepage;
                entity.MODULE_ID = module_id;
                entity.CREATED_DATE = created_date;
                entity.CREATED_BY = created_by;
                entity.MODIFY_DATE = modify_date;
                entity.MODIFY_BY = modify_by;
                entity.LAST_POST_BY = last_post_by;
                entity.LAST_POST_DATE = last_post_date;
                entity.STATUS = status;
                return action.ExecuteAndReturnStringValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Delete(int thread_id)
        {
            try
            {
                BOThreads_Delete action = new BOThreads_Delete();
                usp_Threads_Delete entity = new usp_Threads_Delete();
                entity.THREAD_ID = thread_id;

                return action.ExecuteAndReturnBooleanValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int SetVIP(string thread_code)
        {
            try
            {
                BOThreads_SetVIP action = new BOThreads_SetVIP();
                usp_Threads_SetVIP entity = new usp_Threads_SetVIP();
                entity.THREAD_CODE = thread_code;

                return Convert.ToInt32(action.ExecuteAndReturnStringValue(entity));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Display(int thread_id, bool isdisplay)
        {
            try
            {
                BOThreads_Display action = new BOThreads_Display();
                usp_Threads_Display entity = new usp_Threads_Display();
                entity.THREAD_ID = thread_id;
                entity.IsDisplay = isdisplay;

                return action.ExecuteAndReturnBooleanValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Display(int thread_id)
        {
            try
            {
                BOThread_Display action = new BOThread_Display();
                usp_Thread_Display entity = new usp_Thread_Display();
                entity.THREAD_ID = thread_id;
                return action.ExecuteAndReturnBooleanValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Vip(int thread_id)
        {
            try
            {
                BOThread_Vip action = new BOThread_Vip();
                usp_Thread_Vip entity = new usp_Thread_Vip();
                entity.THREAD_ID = thread_id;
                return action.ExecuteAndReturnBooleanValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Restore(int thread_id)
        {
            try
            {
                BOThreads_Restore action = new BOThreads_Restore();
                usp_Threads_Restore entity = new usp_Threads_Restore();
                entity.THREAD_ID = thread_id;

                return action.ExecuteAndReturnBooleanValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable SelectAdmin(string keyword, int module_id, int category_id, int region_id, int need_id, int startIndex, int pageCount)
        {
            try
            {
                BOThreads_Select_Admin action = new BOThreads_Select_Admin();
                usp_Threads_Select_Admin entity = new usp_Threads_Select_Admin();
                entity.STARTINDEX = startIndex;
                entity.MAXRECORDS = pageCount;
                entity.KEYWORD = keyword;
                entity.MODULE_ID = module_id;
                entity.CATEGORY_ID = category_id;
                entity.REGION_ID = region_id;
                entity.NEED_ID = need_id;

                return action.ExecuteAndReturnDataTable(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Order(int mid, string list_aid_order)
        {
            try
            {
                BOThread_Order action = new BOThread_Order();
                usp_Threads_Order entity = new usp_Threads_Order();
                entity.MID = mid;
                entity.LIST_AID_ORDER = list_aid_order;
                return action.ExecuteAndReturnBooleanValue(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
